package nc.bs.pub.action;

import nc.bs.framework.common.NCLocator;
import nc.bs.pub.action.listener.IPPickAllServer;
import nc.bs.pub.action.listener.lPPickDeliveryServer;
import nc.itf.mmpac.wr.IWrBatchOperateService;
import nc.itf.mmpac.wr.IWrMaintainService;
import nc.vo.mmpac.wr.entity.AggWrVO;
import nc.vo.mmpac.wr.entity.WrItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.bd.bom.bom0202.enumeration.OutputTypeEnum;
import nc.vo.mmpac.wr.consts.WrptLangConst;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

/**
 * 
 * 
 * @author LP
 *
 */

public class IPPickAllIpml implements IPPickAllServer {

	@Override
	public void IPPickAll_RequiresNew(AggWrVO[] aggWrVOs) throws Exception {
		
		AggWrVO[] updateWrVOs = NCLocator.getInstance().lookup(IWrMaintainService.class).update(aggWrVOs);
		 if (null != updateWrVOs && updateWrVOs.length == 1) {
	         WrItemVO[] itemVOs = (WrItemVO[])((WrItemVO[])updateWrVOs[0].getChildren(WrItemVO.class));
	          String billCode = updateWrVOs[0].getParentVO().getVbillcode();
	 
	          if (null == itemVOs || itemVOs.length == 0) {
	             ExceptionUtils.wrappBusinessException(String.format(WrptLangConst.ERR_ItemNull(), billCode));
	         }
	         if (itemVOs.length > 1) {
	             return;
	          }
	 
	          if (!OutputTypeEnum.MAIN_PRODUCT.equalsValue(itemVOs[0].getFbproducttype())) {
	             ExceptionUtils.wrappBusinessException(WrptLangConst.getHIT_WRBILLCODE() + billCode + String.format(WrptLangConst.ERR_NOTMAINPRODUCT(), itemVOs[0].getVbrowno()));
	 
	          }
	 
	          if (UFBoolean.TRUE.equals(itemVOs[0].getBbhaspicked())) {
	             ExceptionUtils.wrappBusinessException(WrptLangConst.getHIT_WRBILLCODE() + billCode + String.format(WrptLangConst.ERR_PICKED(), itemVOs[0].getVbrowno()));
	
	        }
	       }
	
	
		//nc.vo.mmpac.wr.param.WrReturnParamVO aParamVO=NCLocator.getInstance().lookup(lPPickDeliveryServer.class).lPPickDelivery(updateWrVOs);
		nc.vo.mmpac.wr.param.WrReturnParamVO aParamVO=NCLocator.getInstance().lookup(IWrBatchOperateService.class).doPickDelivery(updateWrVOs);
		
	
		
	     
		
		if (aParamVO.getExcpMsgList()!=null) {
			nc.vo.mmpac.wr.param.WrReturnParamVO aParamVOaParamVO=NCLocator.getInstance().lookup(IWrBatchOperateService.class).doUnPickDelivery(updateWrVOs);
			throw new Exception(aParamVO.getExcpMsgList().get(0).getMessage());
		}
	
	
		
	}

}

